package com.foreknow.springboot.threaddemo;

/**
 * @author xiaoming
 * @version jdk1.8
 * @date 2022/8/11 16:21
 * @function:
 */
public class Thread2 implements Runnable {
    @Override
    public void run() {
        synchronized (WaitAndSleep.class){
            System.out.println("enter Thread2.....");
            System.out.println("enter Thread2 is sleep.....");
            //如果某个线程进入到了wait状态,需要调用来唤醒等待的线程\
            //只有针对此对象调用notify()方法之后本线程才进入到运行状态
            WaitAndSleep.class.notify();
            try {
                //Thread.sleep(5000)这个方法导致了暂停执行指定的时间，让出cpu资源给其他线程
                //这个时候它的监控的状态依然保持着,当指定的时间到了就会恢复运行的状态
                //在调用sleep的方法过程中，线程不会释放对象锁
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread2 is going on....");
            System.out.println("Thread2 is over...");
        }
    }
}
